<?php
class Hero extends AppModel {
	public $name = 'Hero';
	public 	$useTable  = 'heroes';
	
	/* public $hasOne = array(
        'Article' => array(
        'className' => 'Article',
        )); */
	
	function getListHeroes(){
		return $this->find('all');
	}
	function getListHeroesByPeriodId($id){
		return $this->find('all',array(
			'conditions' => array(
				'period_id' => $id
			)
		));
	}
	function getHeroById($id){
		return $this->find('all',array(
			'conditions' => array(
				'id' => $id
			)
		));
	}
	function getHeroesByPeriodId($id){
		$query =" 	SELECT 
						heroes.id,
						heroes.name,
						heroes.year_of_birth,
						heroes.year_of_died,
						heroes.address,
						heroes.image_url
					FROM
						heroes ,
						heroes_periods ,
						periods
					WHERE
						heroes.id =  heroes_periods.hero_id AND
						periods.id =  heroes_periods.period_id AND
						periods.id =  '".$id."'";
		return $this->query($query);
	}
	function getHeroesByName($name){
		return $this->find('all',array(
			'conditions' => array(
				'name like' => '%'.$name.'%'
			)
		));
	}
	
}
?>